package com.easonji.core.log.factory;

import com.easonji.admin.model.LoginLog;
import com.easonji.admin.model.OperationLog;
import com.easonji.common.constant.enums.LogSucceedEnum;
import com.easonji.common.constant.enums.LogTypeEnum;

/**
 * @ClassName: LogFactory
 * @Description: 日志对象创建工厂
 * @Author: LiuJun
 * @date: 2018/07/08 17:48
 * @Version: 1.0
 * @Copyright: Copyright (c) 2018 - 2019
 */
public class LogFactory {

    /**
     * 创建操作日志
     * 
     * @param logType
     *            日志类型
     * @param userId
     *            用户ID
     * @param bussinessName
     *            业务名字
     * @param clazzName
     *            类名
     * @param methodName
     *            方法名
     * @param msg
     *            备注
     * @param succeed
     *            是否成功
     * @return 操作日志对象
     */
    public static OperationLog createOperationLog(LogTypeEnum logType, Integer userId, String bussinessName,
                                                  String clazzName, String methodName, String msg, LogSucceedEnum succeed) {
        OperationLog operationLog = new OperationLog();
        operationLog.setLogType(logType.getMessage());
        operationLog.setLogName(bussinessName);
        operationLog.setUserId(userId);
        operationLog.setClassName(clazzName);
        operationLog.setMethodName(methodName);
        operationLog.setSucceed(succeed.getMessage());
        operationLog.setMessage(msg);
        return operationLog;
    }

    /**
     * 创建登录日志
     * 
     * @param logType
     *            日志类型
     * @param userId
     *            用户ID
     * @param msg
     *            备注
     * @param ip
     *            登陆IP
     * @return 登陆日志对象
     */
    public static LoginLog createLoginLog(LogTypeEnum logType, Integer userId, String msg, String ip) {
        LoginLog loginLog = new LoginLog();
        loginLog.setLogName(logType.getMessage());
        loginLog.setUserId(userId);
        loginLog.setSucceed(LogSucceedEnum.SUCCESS.getMessage());
        loginLog.setLoginIp(ip);
        loginLog.setMessage(msg);
        return loginLog;
    }
}
